/**
 * Copyright 2015-2016 eyaomall.cn
 * All rights reserved.
 *
 * @project
 * @author jackey
 * @version 1.0
 * @date 2016-01-06
 */
package com.eyaomall.wxmanage.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.eyaomall.wxmanage.dao.ReceiptDao;
import com.eyaomall.wxmanage.dao.ShopPaymentRecordDao;
import com.eyaomall.wxmanage.model.po.Receipt;
import com.eyaomall.wxmanage.model.po.ShopPaymentRecord;
import com.eyaomall.wxmanage.service.InvoiceService;
import com.eyaomall.wxmanage.service.ReceiptService;
import com.lycheeframework.core.cmp.kit.IHTTPObject;
import com.lycheeframework.core.cmp.kit.Pages;
/**
 * 应收款单接口
 * @author pro
 *
 */
@Service
public class ReceiptServiceImpl implements ReceiptService {

	@Autowired
	private ReceiptDao receiptDao;
	
	@Autowired
	private ShopPaymentRecordDao recordDao;
	
	@Autowired
	private InvoiceService invoiceService;
	
	/**
	 * 新增应收款登录
	 */
	public Integer create(Receipt receipt) {
		
		return receiptDao.create(receipt);
	}

	/**
	 * 修改应收款已发货
	 */
	@Transactional(propagation=Propagation.REQUIRED)
	public boolean update(Receipt receipt) {
		if("0".equalsIgnoreCase(receipt.getStatus())){
			Receipt tt = receiptDao.queryById(receipt.getId());
			
			ShopPaymentRecord record = new ShopPaymentRecord();
			record.setId(tt.getId());
			//设置订单状态为待发货
			record.setStatus("1");
			recordDao.update(record);
		}
		
		//更新发票信息
		Receipt rp = receiptDao.queryById(receipt.getId());
		invoiceService.hasPay(rp.getOrderId());
		
		return receiptDao.update(receipt);
	}

	/**
	 * 
	 */
	public Pages<?> page(Receipt receipt, IHTTPObject httpObject) {
		
		return receiptDao.page(receipt, httpObject);
	}

}
